package week11;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author The setting sun
 * @version 1.0
 * @title: Work3Server
 * @description: TODO
 * @date 2021/11/18 14:37
 */
public class Work3Server {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(7777);

        Socket clientSocket = ss.accept();
        InputStream is = clientSocket.getInputStream();
        DataInputStream dis = new DataInputStream(is);
        OutputStream os = clientSocket.getOutputStream();
        DataOutputStream dos = new DataOutputStream(os);

        File file = new File("test.jpg");
        FileOutputStream fos = new FileOutputStream(file);

        byte[] bytes = new byte[1024];
        int len = 0;
        while ((len = dis.read(bytes)) != -1) {
            fos.write(bytes);
        }

        fos.close();
        clientSocket.close();
    }
}
